home *** CD-ROM | disk | FTP | other *** search
/ DOpus Plus / DOpus Plus.iso / Tutorial / C Guide / Code_Fragments / GetEntries.c < prev    next >
C/C++ Source or Header  |  1998-09-18  |  3KB  |  123 lines

  1. /* 
  2.  
  3.     GetEntries.c - Read all selected Files from all sources 
  4.  
  5.     Does support a command template with "Name,..." as well
  6.     and does use then only the commandline names.
  7.  
  8.     In case of collecting files from listers it does store
  9.     for each entry the lister and entry pointer too (do not
  10.     forget to free it later...:) )
  11.     
  12. */
  13.  
  14. #include <proto/dos.h>
  15. #include <proto/exec.h>
  16.  
  17. #define _DOPUS_MODULE_DEF
  18. #include <dopus/modules.h>
  19.  
  20. // strcpy() is needed
  21. #define  SDI_TO_ANSI
  22. #include <sdi_std.h>
  23.  
  24. #include <exec/memory.h>
  25.  
  26. typedef struct NodeData
  27. {
  28.        APTR lister;
  29.        APTR entry;
  30. };
  31.  
  32. extern APTR mempool;
  33.  
  34. /********************************************************************/
  35. // Prototypes
  36.  
  37. // the function you should call
  38. Att_List *GetFiles( IPCData *ipc, FuncArgs *fargs, DOpusCallbackInfo *dc );
  39.  
  40. Att_List *GetSourceEntries( IPCData *ipc, DOpusCallbackInfo *dc );
  41. Att_List *GetArgNames(      long     farg );
  42.  
  43. /********************************************************************/
  44.  
  45. Att_List *GetFiles( IPCData *ipc, FuncArgs *fargs, DOpusCallbackInfo *dc )
  46. {
  47.      Att_List *entrylist = NULL;
  48.  
  49.      if( fargs && fargs->FA_Arguments[0] )
  50.           entrylist = GetArgNames( fargs->FA_Arguments[0] );
  51.  
  52.      if( IsListEmpty((struct List *) entrylist) )
  53.        {
  54.           Att_RemList( entrylist, NULL );
  55.           entrylist = GetSourceEntries( ipc, dc );
  56.        }
  57.  
  58.      if( IsListEmpty((struct List *) entrylist) )
  59.        {
  60.           Att_RemList( entrylist, NULL );
  61.           return NULL;
  62.        }
  63.  
  64.      return entrylist;
  65. }
  66.  
  67. /********************************************************************/
  68.  
  69. Att_List *GetSourceEntries( IPCData *ipc, DOpusCallbackInfo *dc )
  70. {
  71.     ULONG num;
  72.     APTR entry, handle;
  73.     char buffer0[256], buffer1[256];
  74.     struct NodeData *nd;
  75.     Att_List *entrylist;
  76.     
  77.     entrylist = Att_NewList( LISTF_POOL );
  78.     
  79.     handle = dc->dc_GetSource( IPCDATA(ipc), buffer0 );
  80.     
  81.     do
  82.       {
  83.          while( (num = dc->dc_ExamineEntry((entry = dc->dc_GetEntry(IPCDATA(ipc))), EE_NAME)) )
  84.            {
  85.               if( (nd=AllocMemH(mempool, sizeof(struct NodeData))) )
  86.                 {
  87.                    nd->lister = handle;
  88.                    nd->entry  = entry;
  89.                    AddPart( strcpy(buffer1, buffer0), (STRPTR) num, 256 );
  90.                    Att_NewNode( entrylist, buffer1, (ULONG) nd, NULL );
  91.                 }
  92.                 
  93.               dc->dc_EndEntry( IPCDATA(ipc), entry, TRUE );
  94.            }
  95.        }
  96.      while( (handle = dc->dc_NextSource(IPCDATA(ipc), buffer0)) );
  97.        
  98.      return entrylist;
  99. }
  100.  
  101. /********************************************************************/
  102.  
  103. Att_List *GetArgNames( long farg )
  104. {
  105.      Att_List *entrylist;
  106.      ULONG *argument_names;
  107.  
  108.      argument_names = (ULONG *) farg;
  109.         
  110.      entrylist = Att_NewList( LISTF_POOL );
  111.     
  112.      do
  113.        {
  114.           Att_NewNode( entrylist, (STRPTR) *(argument_names), NULL, NULL );
  115.        }
  116.      while( *++argument_names );
  117.     
  118.      return entrylist;
  119. }
  120.  
  121. /********************************************************************/
  122.  
  123.